#include "kmkmusic.h"
#include "ui_kmkmusic.h"


kmkMusic::kmkMusic(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::kmkMusic)
    ,currentIndex(-1),isDrag(true)
{
    this->setWindowIcon(QIcon(":/res/icon.png"));
    ui->setupUi(this);
    initUi();

    initPlay();

    initSqlite();


    connectSignalAndSlots();
    ui->stackedWidget->setCurrentIndex(0);
    this->volTool=new VolumeTool(this);
    this->musicList=new MusicList;
    initMusicList();
    currentPage=ui->localPage;
    connect(this->volTool,&VolumeTool::mutedClick,this,&kmkMusic::onMutedClick);
    connect(this->volTool,&VolumeTool::setVolumeVal,this,&kmkMusic::onSetVolumeVal);
}

kmkMusic::~kmkMusic()
{
    delete this->mediaPlayer;
    delete this->volTool;
    delete this->musicList;
    delete this->playList;
    delete ui;
    //qDebug()<<"mediaPlayer:"<<this->mediaPlayer<<" volTool:"<<this->volTool<<" musicList:"<<this->musicList<<" playList:"<<this->playList;
}

void kmkMusic::initUi()
{
    //设置系统托盘
    QSystemTrayIcon *trayIcon=new QSystemTrayIcon(this);
    trayIcon->setIcon(QIcon(":/res/icon.png"));
    trayIcon->show();
    this->setWindowFlags(Qt::FramelessWindowHint);
    //设置托盘菜单
    QMenu*menu=new QMenu();
    menu->addAction("显示",this,&QWidget::showNormal);
    menu->addAction("退出",this,&kmkMusic::onKmkMusicQuit);

    trayIcon->setContextMenu(menu);

    //设置背景透明
    this->setAttribute(Qt::WA_TranslucentBackground);

    //设置阴影
    QGraphicsDropShadowEffect* shadowEffect=new QGraphicsDropShadowEffect(this);
    shadowEffect->setOffset(0,0);
    shadowEffect->setColor("#000000"); //黑色
    shadowEffect->setBlurRadius(0);
    this->setGraphicsEffect(shadowEffect);

    //设置左侧6个选项的icon 文本 pageId
    ui->rec->setBtStyle(":/res/rec.png","推荐",0);
    ui->audio->setBtStyle(":/res/audio.png","电台",1);
    ui->music->setBtStyle(":/res/music.png","音乐馆",2);
    ui->like->setBtStyle(":/res/like.png","喜欢",3);
    ui->local->setBtStyle(":/res/local.png","本地下载",4);
    ui->recent->setBtStyle(":/res/recent.png","最近播放",5);

    //初始化RecBox
    srand(time(nullptr));
    QJsonArray objArr1=this->setRecTextAndImage();
    ui->recMusicBox->initRecBoxUi(objArr1,1);
    QJsonArray objArr2=this->setRecTextAndImage();
    ui->supplyMusicBox->initRecBoxUi(objArr2,2);

    //初始化commanPage    
    ui->likePage->setCommanPageUi("喜欢",":/res/cover/likeCover.jpg");

    ui->localPage->setCommanPageUi("本地",":/res/cover/localCover.jpg");

    ui->recentPage->setCommanPageUi("最近",":/res/cover/recentCover.jpg");

    ui->play->setStyleSheet("#play{background-color:transparent;border-image:url(\":/res/paly.png\");}");


    lrcPage=new LrcPage(this);
    lrcPage->hide();
    lrcPage->setGeometry(0,0,lrcPage->width(),lrcPage->height());

    lrcPageAnime=new QPropertyAnimation(lrcPage,"geometry",this);
    lrcPageAnime->setDuration(300);
    lrcPageAnime->setStartValue(QRect(0,lrcPage->width(),lrcPage->width(),lrcPage->height()));
    lrcPageAnime->setEndValue(QRect(0,0,lrcPage->width(),lrcPage->height()));


}

void kmkMusic::initPlay()
{
    //1.初始化类对象
    this->mediaPlayer=new QMediaPlayer(this);
    this->playList=new QMediaPlaylist(this);

    //2.设置播放模式
    this->playList->setPlaybackMode(QMediaPlaylist::Random);

    //3.设置播放列表
    this->mediaPlayer->setPlaylist(this->playList);

    //4.设置默认音量
    this->mediaPlayer->setVolume(20);


    //信号槽连接

    connect(this->mediaPlayer,&QMediaPlayer::stateChanged,this,&kmkMusic::onPlayStatusChanged);
    connect(this->playList,&QMediaPlaylist::playbackModeChanged,this,&kmkMusic::onPlaybackModeChanged);
    connect(this->playList,&QMediaPlaylist::currentIndexChanged,this,&kmkMusic::onCurrentIndexChanged);
    connect(this->mediaPlayer,&QMediaPlayer::durationChanged,this,&kmkMusic::onDurationChanged);
    connect(this->mediaPlayer,&QMediaPlayer::positionChanged,this,&kmkMusic::onPositionChanged);
    connect(this->mediaPlayer,&QMediaPlayer::metaDataAvailableChanged,this,&kmkMusic::onMetaDataAvailableChanged);
}

void kmkMusic::initSqlite()
{
    //初始化数据库驱动
    sqlite=QSqlDatabase::addDatabase("QSQLITE");

    //设置数据库名称
    sqlite.setDatabaseName("kmkMusic.db");

    //打开数据库
    if(!sqlite.open())
    {
        QMessageBox::critical(this,"ERROR","数据库打开失败");
        return;
    }

    qDebug()<<"数据库打开成功";
    //创建表
    QString sql="CREATE TABLE IF NOT EXISTS musicInfo(\
                 id INTEGER PRIMARY KEY AUTOINCREMENT,\
                 musicId VARCHAR(50) UNIQUE,\
                 musicName VARCHAR(50),\
                 musicSinger VARCHAR(50),\
                 musicCover VARCHAR(50),\
                 musicUrl VARCHAR(50),\
                 duration BIGINT,\
                 isLike INTEGER,\
                 isHistory INTEGER)";
    QSqlQuery query;
    if(!query.exec(sql))
    {
        QMessageBox::critical(this,"ERROR","表创建失败");
        return;
    }
    qDebug()<<"表创建成功";
}

void kmkMusic::initMusicList()
{
    this->musicList->readMusicFromDB();
    qDebug()<<"this->musicList->readMusicFromDB(); end";
    ui->likePage->setMusicPageType(MusicPageType::LIKE_PAGE);
    ui->likePage->reFresh(musicList);

    ui->localPage->setMusicPageType(MusicPageType::LOCAL_PAGE);
    ui->localPage->reFresh(musicList);

    ui->recentPage->setMusicPageType(MusicPageType::HISTORY_PAGE);
    ui->recentPage->reFresh(musicList);
}


void kmkMusic::on_quit_clicked()
{
    this->hide();
}

void kmkMusic::onKmkMusicQuit()
{
    this->musicList->writeMusicToDB();
    this->sqlite.close();
    this->close();
}

void kmkMusic::mousePressEvent(QMouseEvent *event)
{
    if(Qt::LeftButton==event->button())
    {
        isDrag=true;
        this->pos=event->globalPos();
        qDebug()<<"mousePress pos:"<<pos;
         //获取相对偏移
        dragPosition=event->globalPos()-this->geometry().topLeft();
        return;
    }

    QWidget::mousePressEvent(event);
}

void kmkMusic::mouseMoveEvent(QMouseEvent *event)
{
    if(Qt::LeftButton==event->buttons()&&isDrag)
    {

        this->move(event->globalPos()-dragPosition);
        return;
    }

    QWidget::mouseMoveEvent(event);
}

void kmkMusic::connectSignalAndSlots()
{
    connect(ui->rec,&BtForm::BtClick,this,&kmkMusic::onBtFormClick);
    connect(ui->audio,&BtForm::BtClick,this,&kmkMusic::onBtFormClick);
    connect(ui->music,&BtForm::BtClick,this,&kmkMusic::onBtFormClick);
    connect(ui->like,&BtForm::BtClick,this,&kmkMusic::onBtFormClick);
    connect(ui->local,&BtForm::BtClick,this,&kmkMusic::onBtFormClick);
    connect(ui->recent,&BtForm::BtClick,this,&kmkMusic::onBtFormClick);

    connect(ui->likePage,&CommanPage::updateLikeMusic,this,&kmkMusic::updateLikeMusicAndPage);
    connect(ui->localPage,&CommanPage::updateLikeMusic,this,&kmkMusic::updateLikeMusicAndPage);
    connect(ui->recentPage,&CommanPage::updateLikeMusic,this,&kmkMusic::updateLikeMusicAndPage);

    connect(ui->likePage,&CommanPage::moreSet,this,&kmkMusic::onMoreSet);
    connect(ui->localPage,&CommanPage::moreSet,this,&kmkMusic::onMoreSet);
    connect(ui->recentPage,&CommanPage::moreSet,this,&kmkMusic::onMoreSet);

    connect(ui->likePage,&CommanPage::playAllClick,this,&kmkMusic::onPlayAllClick);
    connect(ui->localPage,&CommanPage::playAllClick,this,&kmkMusic::onPlayAllClick);
    connect(ui->recentPage,&CommanPage::playAllClick,this,&kmkMusic::onPlayAllClick);

    connect(ui->likePage,&CommanPage::playMusicByIndex,this,&kmkMusic::onPlayMusicByIndex);
    connect(ui->localPage,&CommanPage::playMusicByIndex,this,&kmkMusic::onPlayMusicByIndex);
    connect(ui->recentPage,&CommanPage::playMusicByIndex,this,&kmkMusic::onPlayMusicByIndex);

    connect(ui->likePage,&CommanPage::moreItemPlayClick,this,&kmkMusic::onMoreItemPlayClick);
    connect(ui->localPage,&CommanPage::moreItemPlayClick,this,&kmkMusic::onMoreItemPlayClick);
    connect(ui->recentPage,&CommanPage::moreItemPlayClick,this,&kmkMusic::onMoreItemPlayClick);

    connect(ui->likePage,&CommanPage::moreItemNextClick,this,&kmkMusic::onMoreItemNextClick);
    connect(ui->localPage,&CommanPage::moreItemNextClick,this,&kmkMusic::onMoreItemNextClick);
    connect(ui->recentPage,&CommanPage::moreItemNextClick,this,&kmkMusic::onMoreItemNextClick);

    connect(ui->likePage,&CommanPage::moreItemDeleteClick,this,&kmkMusic::onMoreItemDeleteClick);
    connect(ui->localPage,&CommanPage::moreItemDeleteClick,this,&kmkMusic::onMoreItemDeleteClick);
    connect(ui->recentPage,&CommanPage::moreItemDeleteClick,this,&kmkMusic::onMoreItemDeleteClick);

    connect(ui->likePage,&CommanPage::moreItemCommendClick,this,&kmkMusic::onMoreItemCommendClick);
    connect(ui->localPage,&CommanPage::moreItemCommendClick,this,&kmkMusic::onMoreItemCommendClick);
    connect(ui->recentPage,&CommanPage::moreItemCommendClick,this,&kmkMusic::onMoreItemCommendClick);


    connect(ui->progressBar,&MusicSlider::musicSliderChanged,this,&kmkMusic::onMusicSliderChanged);
}

void kmkMusic::onBtFormClick(int id)
{
    ui->stackedWidget->setCurrentIndex(id);

    //清楚其它的背景颜色
    QList<BtForm*> btFormList=this->findChildren<BtForm*>();
    for(auto btForm:btFormList)
    {
        if(btForm->getpageId()!=id)
        {
            btForm->cleanBackground();
            btForm->getEffectLabel()->clear();
        }
    }

    isDrag=false;
}

QJsonArray kmkMusic::setRecTextAndImage()
{
    QVector<QString> vecImageName;
    QFile file(":/res/file/imageName.txt");
    if(!file.open(QIODevice::ReadOnly|QIODevice::Text))
    {
        qWarning()<<"Cannot open file for reading"<<file.errorString();
        return QJsonArray();
    }
    QString imageName;
    while(!file.atEnd())
    {
        char buffer[1];
        qint64 charRead=file.read(buffer,sizeof(buffer));
        if(charRead==-1)
        {
            qWarning()<<"Error reading file: "<<file.errorString();
            break;
        }
        else if(charRead>0)
        {
            if(buffer[0]==' ')
            {
                vecImageName<<imageName;
                //qDebug()<<imageName<<" ";
                imageName="";
            }
            else if(buffer[0]=='\n')
            {
                //qDebug()<<"换行";
            }
            else
                imageName+=buffer[0];
        }
    }
    file.close();
    std::random_shuffle(vecImageName.begin(),vecImageName.end());
    QJsonArray objArr;
    for(int i=0;i<vecImageName.size();i++)
    {
        QJsonObject obj;
        obj.insert("path",":/res/musicImage/"+vecImageName[i]);
        char tmp[4];
        sprintf(tmp,"%03d",i+1);
        //QString recText="推荐-%i"+QString().arg(i,3,10,QChar('0'));
        QString tmpText=tmp;
        QString recText="推荐-"+tmpText;
        obj.insert("text",recText);
        objArr.append(obj);
    }
    return objArr;

}

void kmkMusic::on_min_clicked()
{
    this->showMinimized();
}

void kmkMusic::on_volume_clicked()
{
    QPoint point=ui->volume->mapToGlobal(QPoint(0,0));
    QPoint volPoint=point-QPoint((volTool->width()-ui->volume->width())/2,volTool->height());
    volTool->move(volPoint);
    volTool->show();
}

void kmkMusic::on_addLocal_clicked()
{
     QFileDialog fileDialog(this);
     fileDialog.setWindowTitle("添加本地文件");

     QDir dir(QDir::currentPath());
     dir.cdUp();
     QString path=dir.path();
     path+="/kmkMusic";
     fileDialog.setDirectory(path);

     //设置一次打开多个文件
     fileDialog.setFileMode(QFileDialog::ExistingFiles);

     //设置打开的文件MIME
     QStringList strList={"音频文件(*.mp3)","音频文件(*.flac)","音频文件(*.wav)"};
     fileDialog.setNameFilters(strList);

     if(QDialog::Accepted==fileDialog.exec())
     {
         //qDebug()<<"添加文件 start";
         QList<QUrl> fileUrls=fileDialog.selectedUrls();
         //qDebug()<<"fileUrls selected";
         musicList->addMusicsByUrl(fileUrls);
          //qDebug()<<"添加文件 end";
         ui->localPage->reFresh(musicList);
         ui->localPage->addMusicToPlayList(musicList,playList);

     }

}

void kmkMusic::updateLikeMusicAndPage(bool isLike, const QString &musicId)
{
    if(this->musicList==nullptr)
    {
        qDebug()<<"musicList==nullptr";
        return;
    }
    auto it=this->musicList->findMusicByMusicId(musicId);

    //1.更新isLike状态  2.更新页面
    if(it!=this->musicList->end())
    {
        it->setIsLike(isLike);
    }

    //qDebug()<<"kmkMusic::updateLikeMusicAndPage(bool isLike, const QString &musicId)";
    ui->likePage->reFresh(this->musicList);
    ui->localPage->reFresh(this->musicList);
    ui->recentPage->reFresh(this->musicList);
}


//播放控制区
void kmkMusic::on_play_clicked()
{
    qDebug()<<"void kmkMusic::on_play_clicked()";
    if(mediaPlayer->state()==QMediaPlayer::PlayingState)  //正在播放状态
    {
        mediaPlayer->pause();
    }
    else if(mediaPlayer->state()==QMediaPlayer::PausedState)  //暂停播放状态
    {
        mediaPlayer->play();
    }
    else if(mediaPlayer->state()==QMediaPlayer::StoppedState)  //停止播放状态
    {
        mediaPlayer->play();
    }
    else
    {
        qDebug()<<mediaPlayer->errorString();
    }

}



void kmkMusic::on_playUp_clicked()
{
    //qDebug()<<"void kmkMusic::on_playUp_clicked()";
   this->playList->previous();
}

void kmkMusic::on_playDown_clicked()
{
     //qDebug()<<"void kmkMusic::on_playDown_clicked()";
    this->playList->next();
}

void kmkMusic::on_playMode_clicked()
{
    //随机播放->列表循环->单曲循环->随机播发
    if(this->playList->playbackMode()==QMediaPlaylist::Random)
    {
        this->playList->setPlaybackMode(QMediaPlaylist::Loop);
        ui->playMode->setToolTip("列表循环");
    }
    else if(this->playList->playbackMode()==QMediaPlaylist::Loop)
    {
        this->playList->setPlaybackMode(QMediaPlaylist::CurrentItemInLoop);
        ui->playMode->setToolTip("单曲循环");
    }
    else if(this->playList->playbackMode()==QMediaPlaylist::CurrentItemInLoop)
    {
        this->playList->setPlaybackMode(QMediaPlaylist::Random);
        ui->playMode->setToolTip("随机播放");
    }
    else
    {
        qDebug()<<"暂未支持";
    }
}

void kmkMusic::onPlayAllClick(MusicPageType pageType)
{
    CommanPage *page=ui->localPage;
    switch(pageType)
    {
    case MusicPageType::LIKE_PAGE:
        page=ui->likePage;
        break;
    case MusicPageType::LOCAL_PAGE:
        page=ui->localPage;
        break;
    case MusicPageType::HISTORY_PAGE:
        page=ui->recentPage;
        break;
    default:
        qDebug()<<"暂不支持的页面";
        break;
    }

    this->playAllMusicOfPage(page,0);
}

void kmkMusic::onPlayMusicByIndex(CommanPage *page, int index)
{
    //qDebug()<<"void kmkMusic::onPlayMusicByIndex(CommanPage *page, int index)";
    this->currentPage=page;
    //qDebug()<<"void kmkMusic::onPlayMusicByIndex(CommanPage *page, int index)";
    this->playAllMusicOfPage(page,index);
}

void kmkMusic::playAllMusicOfPage(CommanPage *page, int index)
{
    this->currentPage=page;
    this->playList->clear();

    page->addMusicToPlayList(this->musicList,this->playList);

    this->playList->setCurrentIndex(index);

    this->mediaPlayer->play();
}

void kmkMusic::onCurrentIndexChanged(int index)
{
    //qDebug()<<"void kmkMusic::onCurrentIndexChanged(int index)";
    this->currentIndex=index;
    QString musicId=currentPage->getMusicIdByIndex(index);

    auto music=musicList->findMusicByMusicId(musicId);
    if(music!=musicList->end())
    {
        music->setIsHistory(true);
    }
    ui->recentPage->reFresh(this->musicList);
}

void kmkMusic::onPlayStatusChanged()
{
    //qDebug()<<"void kmkMusic::onPlayStatusChanged()";
    if(this->mediaPlayer->state()==QMediaPlayer::StoppedState)
    {
        ui->play->setStyleSheet("#play{background-color:transparent;border-image:url(\":/res/paly.png\");}");
    }
    else if(this->mediaPlayer->state()==QMediaPlayer::PausedState)
    {
        ui->play->setStyleSheet("#play{background-color:transparent;border-image:url(\":/res/paly.png\");}");
    }
    else if(this->mediaPlayer->state()==QMediaPlayer::PlayingState)
    {
        ui->play->setStyleSheet("#play{background-color:transparent;border-image:url(\":/res/pause.png\");}");
    }
    else
    {
         qDebug()<<mediaPlayer->errorString();
    }
}

void kmkMusic::onMutedClick(bool isMuted)  //静音
{
    //qDebug()<<"void kmkMusic::onMutedClick(bool isMuted)";
    this->mediaPlayer->setMuted(isMuted);
}

void kmkMusic::onSetVolumeVal(int volumeVal)
{
    this->mediaPlayer->setVolume(volumeVal);
}

void kmkMusic::onDurationChanged(qint64 duration)
{
    //qDebug()<<"void kmkMusic::onDurationChanged(qint64 duration)";
    //min: duration/1000/60
    //sec: duration/1000%60
    this->totalTime=duration;

    ui->totalTime->setText(QString("%1:%2").arg(duration/1000/60,2,10,QChar('0')).arg(duration/1000%60,2,10,QChar('0')));
}

void kmkMusic::onPositionChanged(qint64 position)
{
    //qDebug()<<"void kmkMusic::onPositionChanged(qint64 position)";
    ui->currentTime->setText(QString("%1:%2").arg(position/1000/60,2,10,QChar('0')).arg(position/1000%60,2,10,QChar('0')));

    ui->progressBar->setStep(position/(float)totalTime);

    if(currentIndex>=0)
    {
        this->lrcPage->showLrcWordLine(position);
    }
}

void kmkMusic::onMusicSliderChanged(float rate)
{
    qint64 duration=this->totalTime*rate;

    ui->currentTime->setText(QString("%1:%2").arg(duration/1000/60,2,10,QChar('0')).arg(duration/1000%60,2,10,QChar('0')));

    this->mediaPlayer->setPosition(duration);
}

void kmkMusic::onMetaDataAvailableChanged(bool available)
{
    //qDebug()<<"void kmkMusic::onMetaDataAvailableChanged(bool available)";
    (void)available;
    QString musicId=this->currentPage->getMusicIdByIndex(currentIndex);
    auto music=this->musicList->findMusicByMusicId(musicId);
    QString musicName="未知歌曲";
    QString musicSinger="未知歌手";

    if(music!=musicList->end())
    {
        musicName=music->getMusicName();
        musicSinger=music->getMusicSinger();
    }

    ui->musicName->setText(musicName);
    ui->musicSinger->setText(musicSinger);
    this->lrcPage->setNameAndSinger(musicName,musicSinger);

    //设置封面
    QVariant variant=this->mediaPlayer->metaData("ThumbnailImage");
    if(variant.isValid())
    {
        QImage image=variant.value<QImage>();
        ui->musicCover->setPixmap(QPixmap::fromImage(image));
    }
    else
    {
        QString path=":/res/cover/defaultCover.jpg";
        ui->musicCover->setPixmap(path);
    }

    ui->musicCover->setScaledContents(true);

    if(music!=musicList->end())
    {
        QString lrcpath=music->getLrcFile();
        this->lrcPage->parseLrcFile(lrcpath);


    }


}

void kmkMusic::onPlaybackModeChanged(QMediaPlaylist::PlaybackMode mode)
{
    //qDebug()<<"void kmkMusic::onPlaybackModeChanged(QMediaPlaylist::PlaybackMode mode)";
    if(mode==QMediaPlaylist::Random)
    {
        ui->playMode->setStyleSheet("#playMode{background-color:transparent;border-image:url(\":/res/random.png\");}");
    }
    else if(mode==QMediaPlaylist::Loop)
    {
        ui->playMode->setStyleSheet("#playMode{background-color:transparent;border-image:url(\":/res/listLoop.png\");}");
    }
    else if(mode==QMediaPlaylist::CurrentItemInLoop)
    {
        ui->playMode->setStyleSheet("#playMode{background-color:transparent;border-image:url(\":/res/singleLoop.png\");}");
    }
    else
    {
        qDebug()<<"暂未支持";
    }
}

void kmkMusic::on_lrcWord_clicked()
{
    lrcPage->show();
    lrcPageAnime->start();
}

void kmkMusic::onMoreSet(QMenu*menu,int width,int height)
{

//    qDebug()<<"void kmkMusic::onMoreShow(QPoint topRight)";
//    qDebug()<<"相对:"<<topRight;
//    QPoint pos=this->mapToGlobal(topRight);  //转换为绝对坐标
//    qDebug()<<"绝对:"<<pos;
//    //this->moreBtBox->move(pos.x(),pos.y());
//    this->moreBtBox->setGeometry(pos.x(),pos.y(),this->moreBtBox->width(),this->moreBtBox->height());
//    this->moreBtBox->show();
//    //this->moreBtBox->setCurrentIndex(this->playList->currentIndex());
     //创建菜单项
//    QAction *playAction = new QAction("播放", this);
//    QAction *nextAction = new QAction("下一首播放", this);
//    QAction *commentAction = new QAction("查看评论", this);
//    QAction *removeFromPlaylistAction = new QAction("从歌单中删除", this);

//    // 添加菜单项到菜单中
//    menu->addAction(playAction);
//    menu->addAction(nextAction);
//    menu->addAction(commentAction);
//    menu->addAction(removeFromPlaylistAction);
//    connect(playAction,&QAction::triggered,this,&kmkMusic::on_play_clicked);
//    qDebug()<<"移动前坐标:"<<menu->pos();
//    qDebug()<<"pos坐标:"<<pos;
    //    menu->show();  // 显示菜单
}

void kmkMusic::onMoreItemPlayClick(const QString &musicId)
{
    qDebug()<<"void kmkMusic::onMoreItemPlayClick()";
    int index=0;
    for(auto music:*musicList)
    {
        if(musicId==music.getMusicId())
        {
            this->onPlayMusicByIndex(this->currentPage,index);
            break;
        }
        index++;
    }

}

void kmkMusic::onMoreItemNextClick(const QString &musicId)
{
    int index=0;
    for(auto music:*musicList)
    {
        if(musicId==music.getMusicId())
        {
            break;
        }
        index++;
    }
    this->playList->setCurrentIndex(index);
}

void kmkMusic::onMoreItemDeleteClick(const QString &musicId)
{
    qDebug()<<"void kmkMusic::onMoreItemDeleteClick(const QString &musicId)";
    int index=0;
    for(auto music:*musicList)
    {
        if(musicId==music.getMusicId())
        {
            this->playList->removeMedia(index);
            this->musicList->removeMusicByMusicid(musicId);
            QSqlQuery query;
            query.prepare("delete from musicInfo where musicId=?");
            query.addBindValue(musicId);
            if(!query.exec())
            {
               qDebug()<<"删除歌曲失败:"<<query.lastError().text();
               return;
            }

            this->currentPage->reFresh(musicList);
            break;
        }
        index++;
    }
}

void kmkMusic::onMoreItemCommendClick(const QString &musicId)
{

}























